package org.duiduo.service.impl;

import org.duiduo.service.SendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

/**
 * 邮箱发送消息业务层
 * 
 * @author 夜泷noga
 */
@Slf4j
@Service
@PropertySource(value = "classpath:mail.properties", encoding = "UTF-8")
public class SendMessageServiceImpl implements SendMessageService {

    @Value("${mail.from}")
    private String from;

    @Value("${mail.to}")
    private String to;

    @Value("${mail.subject}")
    private String subject;

    @Value("${mail.text}")
    private String text;

    @Autowired
    private JavaMailSender sender;

    @Override
    public void send() {
        // TODO Auto-generated method stub
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(text);
        sender.send(message);
    }

}